package com.gt.admin.controller;

import com.gt.common.annotation.Log;
import com.gt.common.core.controller.BaseController;
import com.gt.common.core.domain.AjaxResult;
import com.gt.common.enums.BusinessType;
import com.gt.admin.domain.TemplateData;
import com.gt.admin.service.ITemplateDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 结构化使用明细controller
 */
@Api(tags = "sc-结构化使用明细")
@RestController
@RequestMapping("/template/data")
public class TemplateDataController extends BaseController {
    @Autowired
    private ITemplateDataService templateDataService;

    /**
     * 新增明细
     */
    @ApiOperation("新增明细")
    @Log(title = "结构化使用明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult insert(@RequestBody TemplateData templateData){
        return toAjax(templateDataService.save(templateData));
    }

    /**
     * 修改明细
     */
    @ApiOperation("修改明细")
    @Log(title = "结构化使用明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult update(@RequestBody TemplateData templateData){
        return toAjax(templateDataService.updateById(templateData));
    }

    /**
     * 删除明细
     */
    @ApiOperation("删除明细")
    @Log(title = "结构化使用明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable("ids") Long[] ids){
        return toAjax(templateDataService.removeByIds(Arrays.asList(ids)));
    }
}
